package com.qianfeng.alibaba.provider.controller;

//
//                            _ooOoo_  
//                           o8888888o  
//                           88" . "88  
//                           (| -_- |)  
//                            O\ = /O  
//                        ____/`---'\____  
//                      .   ' \\| |// `.  
//                       / \\||| : |||// \  
//                     / _||||| -:- |||||- \  
//                       | | \\\ - /// | |  
//                     | \_| ''\---/'' | |  
//                      \ .-\__ `-` ___/-. /  
//                   ___`. .' /--.--\ `. . __  
//                ."" '< `.___\_<|>_/___.' >'"".  
//               | | : `- \`.;`\ _ /`;.`/ - ` : | |  
//                 \ \ `-. \_ __\ /__ _/ .-` / /  
//         ======`-.____`-.___\_____/___.-`____.-'======  
//                            `=---='  
//  
//         .............................................  
//                  佛祖镇楼                  BUG辟易  
//          佛曰:  
//                  写字楼里写字间，写字间里程序员；  
//                  程序人员写程序，又拿程序换酒钱。  
//                  酒醒只在网上坐，酒醉还来网下眠；  
//                  酒醉酒醒日复日，网上网下年复年。  
//                  但愿老死电脑间，不愿鞠躬老板前；  
//                  奔驰宝马贵者趣，公交自行程序员。  
//                  别人笑我忒疯癫，我笑自己命太贱；  
//  


import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.qianfeng.alibaba.provider.fallback.FallbackClass;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Random;

/**
 * Created by jackiechan on 20-8-5 上午10:41 没有文学素养长得丑并且耳聋的张俊波
 *
 * @Author jackiechan
 */
@RestController
public class TestController {
    Random random = new Random();

    @Value("${server.port}")
    private int port;

    @RequestMapping("/test1")
    public String test1() {
        return "suibian xie de teste1" + port;
    }

    @RequestMapping("/test2")
    public String test2() {
        return "test2" + port;
    }


    @RequestMapping("/test3")
    public String test3() {
//        try {
//            Thread.sleep(1000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
        int i = 1 / 0;
        return "test3===>" + test1();
    }

    @RequestMapping("/test4")
    @SentinelResource(value = "test4", blockHandler = "yinggaicaidaole" ,fallback = "niyeyinggaicaidaole",fallbackClass ={FallbackClass.class} ,exceptionsToIgnore ={ArithmeticException.class} ) //类似于 hystrixcommond
    public String test4(String name, String password, HttpServletRequest request) {
        System.err.println(request.getRemoteAddr());
        if (random.nextInt(5)==1) {
            int i = 1 / 0;
        }
        return "name--->" + name + "   password=====>" + password;
    }


    public String yinggaicaidaole(String name, String password, HttpServletRequest request, BlockException exception) {
        System.err.println(exception);
        return "zhe shi liu de tong de fan kun de zi shi ";
    }

    public String niyeyinggaicaidaole(String name, String password, HttpServletRequest request) {

        return "xiao xue ming tian jiu yao hui bei jing le , you ren yao cha bu si  fan bu xiang ,wu xin yu xue xi , mei tian yi lei xi mian   ";
    }

}
